#define _CRT_SECURE_NO_WARNINGS 1
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
const int N = 1010;
int n, m;
ll ans;
char a[N][N];

bool check(int x, int y) {
	int cnt = 0;
	if (a[x][y] == '#') cnt++;
	if (a[x][y + 1] == '#') cnt++;
	if (a[x + 1][y] == '#') cnt++;
	if (a[x + 1][y + 1] == '#') cnt++;
	if (cnt == 3) return true;
	return false;
}

void dfs(int x, int y) {
	a[x][y] = '.';
	for (int i = -1; i <= 1; i++) {
		for (int j = -1; j <= 1; j++) {
			int nx = x + i, ny = y + j;
			if (nx<1 || nx>n || ny<1 || ny>m || a[nx][ny] == '.') continue;
			dfs(nx, ny);
		}
	}
	return;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 1; i < n; i++) {
		for (int j = 1; j < m; j++) {
			if (check(i, j)) {
				cout << "Bad placement." << endl;
				return 0;
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (a[i][j] == '#') {
				ans++;
				dfs(i, j);
			}
		}
	}
	cout << "There are " << ans << " ships." << endl;
	return 0;
}